package com.example.module_patrol.adapter
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_patrol.R
import com.example.module_patrol.model.PatrolEntity
import com.google.gson.Gson


class PatrolAdapter :RecyclerView.Adapter<PatrolAdapter.PatrolViewHolder>() {
    var pakingList: ArrayList<PatrolEntity> = arrayListOf()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PatrolViewHolder {
        return PatrolViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_point, parent, false)
        )
    }

    override fun getItemCount(): Int {
        return pakingList.size
    }

    fun addParkingList(list: List<PatrolEntity>) {
        pakingList.clear()
        pakingList.addAll(list)
        notifyDataSetChanged()
    }
    fun addSearchParking(entity:PatrolEntity) {
        pakingList.clear()
        pakingList.add(entity)
        notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: PatrolViewHolder, position: Int) {
        holder.pointName.text = pakingList[position].pointName
        holder.pointLocation.text = pakingList[position].pointLocation
        holder.patrolType.text = pakingList[position].patrolType


        //巡检点位类型（空闲、已占用、维修中 通过字典表配置）
        when (pakingList[position].patrolType) {
            "安防巡检" -> {
                holder.patrolType.setBackgroundResource(R.drawable.patrol_type1)
            }
            "保洁巡检" -> {
                holder.patrolType.setBackgroundResource(R.drawable.patrol_type2)
            }
            "日常巡检" -> {
                holder.patrolType.setBackgroundResource(R.drawable.patrol_type3)
            }
            "家居巡检" -> {
                holder.patrolType.setBackgroundResource(R.drawable.patrol_type2)
            }

        }

        holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/patrol/PatrolDetailActivity")
                .navigation()
        }

    }


   inner class PatrolViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val pointName: TextView = itemView.findViewById(R.id.pointName)
        val pointLocation: TextView = itemView.findViewById(R.id.pointLocation)
        val patrolType: TextView = itemView.findViewById(R.id.patrolType)

    }

}







